<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据库并发控制：悲观锁与乐观锁</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #4a6cf7 100%);
            color: white;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .sql-code {
            font-family: 'Courier New', monospace;
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-left: 4px solid #4a6cf7;
        }
        .feature-icon {
            font-size: 1.5rem;
            margin-bottom: 1rem;
            color: #4a6cf7;
        }
        .dropdown:hover .dropdown-content {
            display: block;
        }
        .mermaid {
            background-color: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero min-h-screen flex items-center justify-center px-4 py-20">
        <div class="max-w-4xl text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">数据库并发控制的艺术</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">探索悲观锁与乐观锁的平衡之道</p>
            <div class="animate-bounce mt-8">
                <i class="fas fa-angle-double-down text-3xl opacity-70"></i>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-4 py-16">
        <!-- Introduction -->
        <div class="mb-20 text-center">
            <h2 class="text-3xl font-bold mb-6 font-serif">并发控制的两种哲学</h2>
            <p class="text-lg max-w-3xl mx-auto opacity-80">在多用户环境下，数据库系统需要协调并发事务对共享数据的访问，确保数据一致性和完整性。悲观锁与乐观锁代表了两种截然不同的并发控制策略，各有所长，适用于不同的业务场景。</p>
        </div>

        <!-- Comparison Table -->
        <div class="grid md:grid-cols-2 gap-8 mb-20">
            <div class="card bg-white rounded-xl p-8 shadow-md">
                <div class="text-center mb-6">
                    <i class="fas fa-lock feature-icon"></i>
                    <h3 class="text-2xl font-bold mb-2 font-serif">悲观锁</h3>
                    <p class="text-gray-600">"先锁定，后操作"的保守策略</p>
                </div>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-bold text-lg text-blue-600 mb-2">实现方式</h4>
                        <p>通过数据库锁机制实现，如 <code class="bg-blue-100 px-2 py-1 rounded">SELECT ... FOR UPDATE</code> 或 <code class="bg-blue-100 px-2 py-1 rounded">LOCK IN SHARE MODE</code></p>
                    </div>
                    <div>
                        <h4 class="font-bold text-lg text-blue-600 mb-2">优点</h4>
                        <ul class="list-disc pl-5 space-y-1">
                            <li>有效防止并发事务冲突</li>
                            <li>保证数据强一致性</li>
                        </ul>
                    </div>
                    <div>
                        <h4 class="font-bold text-lg text-blue-600 mb-2">缺点</h4>
                        <ul class="list-disc pl-5 space-y-